/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.business.account.manage.service;

import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.business.account.core.repository.entity.AccountFreezeLogEntity;
import info.peigen.hotpot.business.account.manage.convertor.AccountFreezeLogManageConvertor;
import info.peigen.hotpot.business.account.manage.form.AccountFreezeLogManageCreateForm;
import info.peigen.hotpot.business.account.manage.form.AccountFreezeLogManageEditForm;
import info.peigen.hotpot.business.account.manage.form.AccountFreezeLogManageSearchForm;
import info.peigen.hotpot.business.account.manage.info.AccountFreezeLogManageInfo;
import info.peigen.hotpot.business.account.manage.repository.service.AccountFreezeLogManageRepository;
import info.peigen.hotpot.common.core.result.PageResult;
import org.beetl.sql.core.query.LambdaQuery;
import org.beetl.sql.core.query.Query;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

/**
 * <b>(AccountFreezeLogManageService)</b>
 * 管理后台 "账户冻结解冻记录" 服务
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023-08-29
 */
@SuppressWarnings("unused")
@Component
public class AccountFreezeLogManageService {
    @Inject
    AccountFreezeLogManageRepository accountFreezeLogManageRepository;

    public PageResult<AccountFreezeLogManageInfo> page(AccountFreezeLogManageSearchForm form) {
        LambdaQuery<AccountFreezeLogEntity> lambdaQuery = accountFreezeLogManageRepository.getMapper().createLambdaQuery()
                .andLike(AccountFreezeLogEntity::getAccountId, Query.filterLikeEmpty(form.getAccountId(), false, true))
                .andLike(AccountFreezeLogEntity::getTradeId, Query.filterLikeEmpty(form.getTradeId(), false, true))
                .andLike(AccountFreezeLogEntity::getFreezeType, Query.filterLikeEmpty(form.getFreezeType(), false, true))
                .andLike(AccountFreezeLogEntity::getBopsOperatorId, Query.filterLikeEmpty(form.getBopsOperatorId(), false, true))
                .andLike(AccountFreezeLogEntity::getPartnerId, Query.filterLikeEmpty(form.getPartnerId(), false, true));

        return accountFreezeLogManageRepository.page(form.getPageNum(), form.getPageSize(), lambdaQuery, AccountFreezeLogManageConvertor::convertToInfo);
    }

    public void create(AccountFreezeLogManageCreateForm form) {
        AccountFreezeLogEntity entity = BeanUtil.copyProperties(form, AccountFreezeLogEntity.class);
        accountFreezeLogManageRepository.save(entity);
    }

    public void edit(AccountFreezeLogManageEditForm form) {
        AccountFreezeLogEntity entity = BeanUtil.copyProperties(form, AccountFreezeLogEntity.class);
        accountFreezeLogManageRepository.saveOrUpdate(entity);
    }

    public void remove(Integer id) {
        accountFreezeLogManageRepository.delete(id);
    }
}